package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.qiniu.util.Json;

import io.renren.modules.sys.entity.ContainerEntity;
import io.renren.modules.sys.service.ContainerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

/**
 * 订单跟踪表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-11-26 23:59:51
 */
@RestController
@RequestMapping("sys/container")
public class ContainerController {
	@Autowired
	private ContainerService containerService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	// @RequiresPermissions("sys:container:list")
	public R list(@RequestParam Map<String, Object> params) {
		if (!params.containsKey("orderId")) {
			return R.error("参数错误");
		}
		// System.out.println("onumber=" + params.get("onumber"));
		System.out.println("params=" + JSON.toJSONString(params));
		// params.put("a", 1);
		PageUtils page = containerService.queryPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	// @RequiresPermissions("sys:container:info")
	public R info(@PathVariable("id") Long id) {
		ContainerEntity container = containerService.selectById(id);

		return R.ok().put("container", container);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	// @RequiresPermissions("sys:container:save")
	public R save(@RequestBody ContainerEntity container) {
		container.setState("进行中");
		container.setDeptId(ShiroUtils.getUserEntity().getDeptId());
		containerService.insert(container);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	// @RequiresPermissions("sys:container:update")
	public R update(@RequestBody ContainerEntity container) {
		System.err.println(JSON.toJSONString(container));
		containerService.updateById(container);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete/{id}")
	// @RequiresPermissions("sys:container:delete")
	public R delete(@PathVariable("id") Long id) {
		// System.err.println(JSON.toJSONString(ids));
		//containerService.deleteBatchIds(Arrays.asList(ids));
		containerService.deleteById(id);

		return R.ok();
	}

}
